<?php

//include_once $_SERVER['DOCUMENT_ROOT'] . '/../queue/Equeue.php';

$this->freshSession();
if ($this->user['uid']) {
    $lock_key = 'tianyu_redis_lock_sendmail_' . $this->user['uid'];
    $ok = common_redis()->set($lock_key, 1, array('nx', 'ex' => 60));   //用redis控制用户过快访问的问题，这个OK只有不存在时才会创建，过期时间15秒，即时说，OK第一次访问是为true,接下来30秒内的访问都为false,除非把这个key删除。
    if ($ok) {
        $rechargeId = $this->getRechId();
        $uid = $this->user['uid'];
        $amount = floatval($_POST['amount']);
        $time = date('Y-m-d H:i:s', time());
        $username = $_POST['username'];
        $depositTime = $_POST['depositTime'];
        if ($amount && $uid && $rechargeId && $depositTime && $username) {
            $para = array();
            $para['amount'] = $amount;
            $para['rechargeId'] = $rechargeId;
            $para['actionTime'] = $this->time;
            $para['uid'] = $this->user['uid'];
            $para['username'] = $this->user['username'];
            $para['actionIP'] = $this->ip(true);
            $para['info'] = '支付宝转账充值';
            $para['depositinfo'] = '支付宝昵称:' . $username . '<br>存款时间:' . $depositTime;
            $para['rechType'] = 'alipay';
            $para['code'] = random_char();
            if ($this->insertRow($this->prename . 'member_recharge', $para)) {
                $queue = common_redis()->rPush('queue:tianyu_email',json_encode($para));//入列
                //$taskid = Equeue::enterq(['name' => 'sendemail', 'data' => $para]); //入列
                echo '存款信息提交成功，请等待客服审核';
                exit;
            } else {
                common_redis()->del($lock_key); //删除锁
                echo '提交失败,请联系客服处理';
                exit;
            }
        } else {
            common_redis()->del($lock_key); //删除锁
            echo '提交失败';
            exit;
        }
    }else {
        echo '您的请求过于频繁，请等待 '.  common_redis()->ttl($lock_key).' 秒后再操作';
    }
}
?>